package com.aurora.springbootmybatis.service.impl;

import com.aurora.springbootmybatis.entity.Student;
import com.aurora.springbootmybatis.mapper.StudentMapper;
import com.aurora.springbootmybatis.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentServiceImpl implements StudentService {
    StudentMapper studentMapper;

    public StudentServiceImpl() {
    }

    @Autowired
    public void setStudentMapper(StudentMapper studentMapper) {
        this.studentMapper = studentMapper;
    }

    public Student findStuById(Integer id) {
        return this.studentMapper.findById(id);
    }

    public List<Student> findAll() {
        return this.studentMapper.findAll();
    }

    public PageInfo<Student> findAllByPage(Student student, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Student> studentList = this.studentMapper.findByPage(student);
        return new PageInfo(studentList);
    }

    public Boolean saveStu(Student student) {
        return this.studentMapper.insert(student);
    }

    public Boolean updateStu(Student student) {
        return this.studentMapper.update(student);
    }

    public Boolean deleteStu(Integer id) {
        return this.studentMapper.deleteById(id);
    }
}
